package com.service.Impl;

import com.dao.UserDao;
import com.pojo.User;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public List<User> findSearchUser(String username) {
        return userDao.searchUser(username);
    }

    public boolean doAddUser(User user) throws Exception {
        int row = userDao.addUser(user);
        if (row>0){
            return true;
        }else {
            throw new Exception("添加失败");
        }
    }

    public boolean doDeleteUser(int id) {
        int row = userDao.deleteUser(id);
        if (row>0){
            return true;
        }else {
            return false;
        }
    }

    public boolean doUpdataUser(User user) {
        int row = userDao.updataUser(user);
        if (row>0){
            return true;
        }else {
            return false;
        }
    }

    public User findUserById(int id) {
        User user = userDao.findUserById(id);
        return user;
    }

    public List<User> findAll() {
        List<User> list = userDao.findAll();
        return list;
    }

    @Override
    public User findLogin(String name, String pwd) {
        return userDao.Login(name,pwd);
    }

    @Override
    public String findPasswordById(int id) {
        return userDao.findPasswordById(id);
    }

    @Override
    public boolean doUpdatePassword(int id, String pwd) {
        int row = userDao.updatePassword(id, pwd);
        if (row>0){
            return true;
        }else {
            return false;
        }
    }
}
